from PySide6.QtWidgets import QToolBar
from weiqi.dlgo.board import Move

from weiqi.dlgo.gotypes import Point

class R:
    ''' 常量和帮助方法 '''

    AppName = 'x01.weiqi'
    AppVersion = '2.0'

    BoardSize = 19
    StoneSize = 35

    @staticmethod
    def AddActions(target, actions):
        for action in actions:
            if action is None:
                if not isinstance(target, QToolBar):
                    target.addSeparator()
            elif isinstance(target, QToolBar) and action.icon is None:
                continue
            else:
                target.addAction(action)


COLS = 'ABCDEFGHJKLMNOPQRST'

def GtpPositionToMove(gtp_position):
    col_str, row_str = gtp_position[0], gtp_position[1:]
    point = Point(int(row_str), COLS.find(col_str.upper()) + 1)
    return Move(point)

def MoveToGtpPosition(move:Move):
    point = move.point
    return COLS[point.col-1]+ str(point.row)

    